package 泛型;

import java.util.Arrays;

class MyArray1<T>{
    Object[] array ;

    public MyArray1(int num) {
        array = new Object[num];
    }
    public void set(int pos, T val){
        array[pos] = val;
    }
    public T get (int pos){
        return (T)array[pos];
    }

    @Override
    public String toString() {
        return "MyArray1{" +
                "array=" + Arrays.toString(array) +
                '}';
    }
    public T[] getArray(){
        return (T[]) array;//向下转型
    }
}
public class Text_2 {
    public static void main(String[] args) {
        MyArray1<Integer> array= new MyArray1<>(3);
        array.set(0,1);
        array.set(1,65);
        System.out.println(array);
        Object[] ss = array.getArray();//写成Object类
        System.out.println(ss);
    }
}
